package com.tledu.cyrus.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author cyrus
 */
public class JdbcUtils {

    private static DataSource dataSource;

    static {
        Properties properties = new Properties();
        try {
            properties.load(
                    JdbcUtils.class.getClassLoader().getResourceAsStream("druid.properties")
            );
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            System.out.println("数据库连接池创建异常");
            throw new RuntimeException(e);
        }
    }

    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }

}
